# 回溯算法-组合
def commbine(n,k):
    result=[]
    path=[]
    def backtracking(n,k,startIndex):
        if len(path)==k:
            result.append(path[:])
            return
        for i in range(startIndex,n+1):
            path.append(i)
            backtracking(n,k,i+1)
            path.pop()
    backtracking(n,k,1)
    return result

lt=commbine(4,2)
print(lt)